package funclib

import (
	"crypto/md5"
	"encoding/hex"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func ToMD5(s string) string {
	m := md5.New()
	m.Write([]byte(s))
	cipherStr := m.Sum(nil)
	return hex.EncodeToString(cipherStr)
}

//ReturnStatues 返回错误json信息
func ReturnBadStatues(c *gin.Context, msg string) {
	c.JSON(http.StatusBadRequest, gin.H{
		"message": msg,
	})
}

//StringListToInt 字符串数组转化为INT
func StringListToInt(l []string) []int {
	var intl []int
	for i := 0; i < len(l); i++ {
		in, _ := strconv.Atoi(l[i])
		intl = append(intl, in)
	}
	return intl
}

//JudgeMonthDay 判断某一个月的最大天数
func JudgeMonthDay(nowMonth string) string {
	a := []string{"01", "03", "05", "07", "08", "10", "12"}
	b := []string{"04", "06", "09", "11"}
	c := []string{"02"}
	for _, v := range a {
		if v == nowMonth {
			return "31"
		}
	}
	for _, v := range b {
		if v == nowMonth {
			return "30"
		}
	}
	for _, v := range c {
		if v == nowMonth {
			return "29"
		}
	}
	return "28"
}
